@extends('layouts.admin')
@section('title')
    <title>来源商铺</title>
@endsection
@section('content')
    @include('layouts.left')
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                Dashboard
                <small>Control panel</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Dashboard</li>
            </ol>
        </section>
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title"><a type="button" class="btn btn-block btn-success" href="{{ url('userinfo') }}/create">来源商店</a></h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body">
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>id</th>
                                    <th>店铺名</th>
                                </tr>
                                </thead>
                                <tbody class="mparent">
                                @foreach($datas as $data)
                                    <tr>
                                     <td>
                                         {{$data -> id}}
                                     </td>
                                     <td>
                                         {{$data -> shopname}}
                                     </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                </div>
            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <!-- 在这里 写js函数-->
    <script type="text/javascript">
        //双击事件
        $(".status").dblclick(function(){
            //获取当前的用户uid
            var uid = $(this).parent().find("input[name='userinfo[]']").val();
            var t = $(this);
            //进行ajax传值
            $.ajaxSetup({
                headers:{
                    'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
                }
            });
            $.ajax({
                url:"{{ url('change_status') }}",
                type:"POST",
                data:{uid:uid},
                success:function(data){
                    if(data.status == 'success_0'){
                        t.html('禁用');
                    }else if(data.status == 'success_1'){
                        t.html('启用');
                    }else{

                    }
                },
                dataType:'json'
            });
        });
        function userinfo_delete(e,id){
            $.ajaxSetup({
                headers:{
                    'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
                }
            });
            var tr = $(e).closest("tr");
            if(confirm("确定要删除此条数据吗？"))
                $.ajax({
                    url:"{{ url('userinfo') }}/"+id,
                    type:"DELETE",
                    data:{id:id},
                    success:function(data){
                        if(data.status == 'have'){
                            alert(data.msg);
                        }else if(data.status == 'success'){
                            alert(data.msg);
                            tr.remove();

                        }else{
                            alert(data.msg);
                        }
                    },
                    dataType:'json'
                });
        }
    </script>
@endsection


